﻿#include "QCefApp.h"


QCefApp::QCefApp()
{
    QCEF_DEBUG();
}

QCefApp::~QCefApp()
{
    QCEF_DEBUG();
}


void QCefApp::checkInClient(void* client)
{
    QCEF_DEBUG();

    m_clients.insert(client);
}

void QCefApp::checkOutClient(void* client)
{
    QCEF_DEBUG();

    m_clients.erase(client);
}

bool QCefApp::isSafeToExit()
{
    return m_clients.empty();
}

//////////////////////////////////////////////////////////////////////////
//CefApp
void QCefApp::OnBeforeCommandLineProcessing(const CefString& process_type,
                                            CefRefPtr<CefCommandLine> command_line)
{
    QCEF_DEBUG();

    //
    QCefConfig* cfg = QCefConfig::instance();
    if (cfg != nullptr)
    {
        QCefConfig::ArgsMap& args = cfg->getArgs();
        for (QCefConfig::ArgsMap::iterator it = args.begin(); it != args.end(); it++)
        {
            if (!it->first.empty() && !command_line->HasSwitch(it->first))
            {
                if (!it->second.empty())
                {
                    command_line->AppendSwitchWithValue(it->first, it->second);
                }
                else
                {
                    command_line->AppendSwitch(it->first);
                }
            }
        }
    }
}


void QCefApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
    QCEF_DEBUG();
}


CefRefPtr<CefResourceBundleHandler> QCefApp::GetResourceBundleHandler()
{
    QCEF_DEBUG();

    return nullptr;
}


CefRefPtr<CefBrowserProcessHandler> QCefApp::GetBrowserProcessHandler()
{
    QCEF_DEBUG();

    return nullptr;
}


CefRefPtr<CefRenderProcessHandler> QCefApp::GetRenderProcessHandler()
{
    QCEF_DEBUG();

    return nullptr;
}
